<?php


include_once("/var/www/html/new/com.inc.php");
include 'common/func.inc.php';
$ac=$GLOBALS['_ac'];
$pw=$GLOBALS['_pw'];
$s = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));

//$mobile=$_REQUEST['mobile'];
//$mobile='18650075419';

//$_REQUEST['action']='register';
//$_SESSION['valiCode']=123456;
$mobile=$_REQUEST['mobile'];
$pwd=substr($mobile,-6);
//echo $pwd;
if($_REQUEST['action']=='获取验证码'){ // 用户点击了发送验证码时执行
    if($mobile==""){
    echo "请先输入手机号";
    exit;
    }
    if(!ismobile($mobile)){
    echo '手机格式不正确';
    exit;
    }
    $time=time();
    $valiCode = getValiCode();
    /*if(abs(substr($valiCode,-2)-substr($_SESSION['valiCode'],-2))<45){
        echo "您操作太频繁，请稍后再试";
        exit();
    }*/
    if($_SESSION['lasttime']!=0){
        if(abs($time-$_SESSION['lasttime'])<60&&$_SESSION['mobile']==$mobile){
        echo "您操作太频繁，请稍后再试";
        exit;
        }
        else{
            $_SESSION['lasttime']=$time;
            $_SESSION['mobile']=$mobile;
        }
        
    }
    $_SESSION['lasttime']=$time;
    $_SESSION['valiCode'] = $valiCode;
    // 发送至手机，成功返回 100
    if($s->Send_SMS_V($mobile,'欢迎使用票付通平台。验证码：'.$valiCode.'，输入验证继续完成操作。',-1)){
        echo 100;
    }else{
        echo 101;
    }
}/*elseif($_REQUEST['action']=='chkPassport'){//验证账户是否存在
    include 'class/MemberAccount.class.php';
    
    $mem = new MemberAccount($GLOBALS['le']);
    $mem->chkPassport($_REQUEST['mobile']);
    
}*/elseif($_REQUEST['action']=='注册'){//注册
    include_once 'class/MemberAccount.class.php';
    $mem = new pft\Member\MemberAccount($GLOBALS['le']);
    $res=$mem->chkPassport($_REQUEST['mobile']);
    $yanzhengma=$_REQUEST['yanzheng'];
    if($res){
        echo "该手机已注册";
        exit;
    }
    if($yanzhengma!=$_SESSION['valiCode']){
        echo "验证码不正确,请重新获取";
        exit;
    }
    $dataMain    = array(
            'mobile' => $mobile,
            'dtype'  => 5,
            'password'  => md5(md5($pwd)),
            );
            echo 'suss';
            
    $result = $mem->register($dataMain);
        if($result['status']!='ok') {
            echo '{"status":"fail","msg":"用户注册失败。失败原因：'.
                $result['msg'].'"}';
        }
        else{
            echo "用户注册成功";
        }
}

function getValiCode(){
    $valiCode = '';
    for($i=0;$i<4;$i++){
        $valiCode .= mt_rand(0,9);
    }
    $valiCode .=date('s');
    return $valiCode;
}




?>